package cn.wl.hrm.service.impl;

import cn.wl.hrm.domain.CourseResource;
import cn.wl.hrm.mapper.CourseResourceMapper;
import cn.wl.hrm.service.ICourseResourceService;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author wl
 * @since 2020-04-21
 */
@Service
public class CourseResourceServiceImpl extends ServiceImpl<CourseResourceMapper, CourseResource> implements ICourseResourceService {

    @Override
    public void saveResource(CourseResource courseResource) {
        //创建一个CourseResource对象
        CourseResource courseResource1 = new CourseResource();
        //设置courseId给新创建的对象
        courseResource1.setCourseId(courseResource.getCourseId());
        //获取传过来的图片路径
        String resources = courseResource.getResources();
        //判断resources是否有值
        if(!StringUtils.hasLength(resources)){
           throw new RuntimeException("图片路径异常");
        }
        //对图片进行截取，遍历一个一个的保存
        String[] split = resources.split(",");
        for (int i = 1; i < split.length; i++) {
            courseResource1.setResources(split[i]);
            baseMapper.insert(courseResource1);
        }
    }
}
